package com.common.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

public class PropertiesUtils {
	
	private static Properties PRO;
	
	private PropertiesUtils(String URL){
		PRO = new Properties();
		try {
			PRO.load(new FileInputStream(new File(URL)));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	
	private PropertiesUtils(File profile){
		PRO = new Properties();
		try {
			PRO.load(new FileInputStream(profile));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	private PropertiesUtils(FileInputStream proFileInputStream){
		PRO = new Properties();
		try {
			PRO.load(proFileInputStream);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 方法名:getInstance
	 * 方法作用:	获得 PropertiesUtils 类实例
	 * @param URL	配置文件 绝对路径
	 * @return	PropertiesUtils 类实例
	 */
	public static PropertiesUtils getInstance(String URL){
		return new PropertiesUtils(URL); 
	}
	
	/**
	 * 方法名:getInstance
	 * 方法作用:	获得 PropertiesUtils 类实例
	 * @param profile	配置文件实例
	 * @return	PropertiesUtils 类实例
	 */
	public static PropertiesUtils getInstance(File profile){
		return new PropertiesUtils(profile); 
	}
	
	/**
	 * 方法名:getInstance
	 * 方法作用:	获得 PropertiesUtils 类实例
	 * @param proFileInputStream	配置文件输入流
	 * @return	PropertiesUtils 类实例
	 */
	public static PropertiesUtils getInstance(FileInputStream proFileInputStream){
		return new PropertiesUtils(proFileInputStream); 
	}
	
	public static String getValue(String key){
		return PRO.getProperty(key);
	}
}
